﻿namespace Resharper.Abstractions.CodeDom.TypeMembers
{
  using System;
  using JetBrains.Annotations;
  using JetBrains.ReSharper.Psi.CSharp.Tree;
  using JetBrains.ReSharper.Psi.Tree;
  using Resharper.Abstractions.CodeDom.Expressions;
  using Resharper.Abstractions.CodeDom.TypeMembers.Fields;
  using Resharper.Abstractions.CodeDom.TypeMembers.Methods;

  /// <summary>Defines the <see cref="ExpressionFactory"/> class.</summary>
  internal static class TypeMemberFactory
  {
    #region Public Methods

    /// <summary>Gets the expression.</summary>
    /// <param name="typeMember">The type member.</param>
    /// <returns>Returns the expression.</returns>
    [NotNull]
    public static TypeMember GetTypeMember([NotNull] ITypeMemberDeclaration typeMember)
    {
      if (typeMember == null)
      {
        throw new ArgumentNullException("typeMember");
      }

      if (typeMember is IMethodDeclaration)
      {
        return new Method((IMethodDeclaration)typeMember);
      }

      if (typeMember is IFieldDeclaration)
      {
        return new Field((IFieldDeclaration)typeMember);
      }

      return new TypeMember(typeMember);
    }

    #endregion
  }
}